package club.babyf.nativeai.demo.algorithm;

/**
 * BubbleSort.
 *
 * @author zhanglei.
 * @date 2025/4/12 16:35.
 * @description 冒泡排序.
 */
public class _10_BubbleSort {

    public void bubbleSort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            for (int j = 0; j < arr.length - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                }
            }
        }
    }

    private void print(int[] arr) {
        for (int i : arr) {
            System.out.print(i);
        }
        System.out.println();
    }

    public static void main(String[] args) {
        int[] arr = {3, 6, 2, 9, 8, 1, 6};
        _10_BubbleSort bubbleSort = new _10_BubbleSort();
        bubbleSort.print(arr);
        bubbleSort.bubbleSort(arr);
        bubbleSort.print(arr);
    }

}
